//
//  KLEditViewController.m
//  KISSLOCK
//
//  Created by 华杨科技 on 2017/4/19.
//  Copyright © 2017年 陈宾鹏. All rights reserved.
//
//  编辑真实姓名和身份证号VC

#import "KLEditViewController.h"
#import "KLRNCCustomView.h"
#import "HemaConst.h"
#import "KLHelp.h"
#import "JRToast.h"

@interface KLEditViewController ()
@property (nonatomic, strong)KLRNCCustomView *customView;
@end

// 编辑姓名或身份证VC
@implementation KLEditViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self navSet];
    
    if ([self.title isEqualToString:@"编辑真实姓名"]) {
        
        self.customView = [[KLRNCCustomView alloc] initWithFrame:CGRectMake(0, 20, UI_View_Width, 300) Title:@"真实姓名:" textPlaceholder:@"请输入真实姓名" btntitle:@"确定" buttonHandler:^(UIButton *sureBtn) {
            [sureBtn addTarget:self action:@selector(nameSureAction:) forControlEvents:(UIControlEventTouchUpInside)];
        }];
    }else if ([self.title isEqualToString:@"编辑身份证号"]) {
        self.customView = [[KLRNCCustomView alloc] initWithFrame:CGRectMake(0, 20, UI_View_Width, 300) Title:@"身份证号:" textPlaceholder:@"请输身份证号" btntitle:@"确定" buttonHandler:^(UIButton *sureBtn) {
            [sureBtn addTarget:self action:@selector(identityCardSureAction:) forControlEvents:(UIControlEventTouchUpInside)];
        }];

    }
    
    [self.view addSubview:self.customView];
}
// 真实姓名确定按钮
- (void)nameSureAction:(UIButton *)sender {
    NSString *realName = self.customView.inputBoxTF.text;
    if (realName.length) {
        [[NSUserDefaults standardUserDefaults] setObject:realName forKey:@"realName"];
        [self.navigationController popViewControllerAnimated:YES];
    }else {
        [JRToast showWithText:@"请输入姓名" duration:0.5];
    }
}
// 身份证确定按钮
- (void)identityCardSureAction:(UIButton *)sender {

    NSString *identityCard = self.customView.inputBoxTF.text;
    if ([KLHelp isIdentityStringIegal:identityCard]) {
        [[NSUserDefaults standardUserDefaults] setObject:identityCard forKey:@"identityCard"];
        [self.navigationController popViewControllerAnimated:YES];
    }else {
        [JRToast showWithText:@"请人输入真实身份证号" duration:0.5];
    }
}

- (void)navSet {
    self.view.backgroundColor = RGB_UI_COLOR(242, 242, 242);
    
    [KLHelp navSet:self doBackHandeler:^(UIButton *backButton) {
        [backButton addTarget:self action:@selector(doback:) forControlEvents:(UIControlEventTouchUpInside)];
    }];
}- (void)doback:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
